/**
*      author: Y_Yao
*      created: 2025-05-10 16:52:46
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 26 + 7;
unordered_map<char,int> bin;
unordered_map<char,vector<char>> mp;
unordered_set<string> S;
int n,m;

bool toposort()
{
    queue<char> q;
    for(char i = 'A';i <= 'Z';i++)
    {
        if(bin[i] == 0) q.push(i);
    }

    while(!q.empty())
    {
        
    }
}

void solve()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i++)
    {
        string s;
        cin >> s;
        if(S.count(s)) continue;
        S.insert(s);
        char a,b;
        a = s[0];
        b = s[2];
        mp[a].push_back(b);
        bin[b]++;

    }
    if(S.size() < n - 1)
    {
        cout << "Sorted sequence cannot be determined." << endl;
        return;
    }

    toposort();
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}